<!-- 我的弹窗 -->

<template>
  <WebModal small>
    <WebForm>
      <FormSlot label="发布对象" bind="rolePlatform">
        <FormSwitch v-bind="getSwitchProps(0)" @change="changeSwitch" />
        <FormSwitch v-bind="getSwitchProps(1)" @change="changeSwitch" />
      </FormSlot>

      <FormPhoto label="图片" bind="fileUrl" folder="carousel" :max="2" row5 required @uploaded="uploaded" />

      <FormLink label="跳转链接" bind="landingPage" />
    </WebForm>
  </WebModal>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'MyModal',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb()],

  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('./', true, /vue$/)),

  /**
   * 监听属性 (深度 deep 首次 immediate)
   */
  watch: {
    /**
     * 监听单项
     */
    one: {
      immediate: true,
      handler() {
        this.changeSwitch()
      },
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 获取开关属性
     */
    getSwitchProps(index) {
      const { TYPE } = this.DICT
      return {
        bind: TYPE[index][0],
        text: TYPE[index][1],
        isCheckbox: true,
        noLabel: true,
        quar: true,
      }
    },

    /**
     * 切换开关
     */
    changeSwitch() {
      const { publishLogistics: app, publishStaff: user } = this.one
      const allFlase = app === 2 && user === 2
      this.one.publishObject = allFlase ? '' : 'ready'
    },

    /**
     * 上传完成
     */
    uploaded(fileName) {
      this.one.fileName = fileName
    },
  },
}
</script>
